#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS     5
#define SZ     50

void *PrintHello(void *threadid);
int data[SZ];

void *PrintHello(void *threadid)
{
  int id = (int)threadid;
  printf("hello world! From thread %i\n", id);
  for (int i = 0; i < 10; i++) {
	  data[id * 10 + i] = rand()%SZ;
  }
  pthread_exit(threadid);
}

int thread_starter (int argc, char *argv[])
{
   pthread_t threads[NUM_THREADS];
   void * status;

   for(int t = 0; t < NUM_THREADS; t++){
      printf("hello world! from main(). Creating thread %i\n", t);
      int rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
   }

   for (int j = 0; j < NUM_THREADS; j++) {
	   pthread_join(threads[j], &status);
   }

   for(int i = 0; i < SZ; i++) {
	   printf("\n Array built %d", data[i]);
   }
   /* Last thing that main() should do */
   pthread_exit(NULL);
}
